Here's the code I mentioned above.
private void tagWorkItems(IWorkItemHandle[] workItemHandles, IBuildResult buildResult,
ITeamRepository teamRepository) throws TeamRepositoryException {
ILinkManager linkManager = (ILinkManager) teamRepository.getClientLibrary(ILinkManager.class);
List unlinkedWorkItems = findUnlinkedWorkItems(workItemHandles, buildResult, linkManager);
List links = new ArrayList();
List workItems = teamRepository.itemManager().fetchCompleteItems(unlinkedWorkItems, IItemManager.REFRESH, null);
for (int i = 0; i < unlinkedWorkItems.size(); ++i) {
IWorkItemHandle workItemHandle = (IWorkItemHandle) unlinkedWorkItems.get(i);
IWorkItem workItem = (IWorkItem) workItems.get(i);
links.add(createLink(teamRepository, workItemHandle, workItem, buildResult));
}
linkManager.saveLinks(links, null);
}
private ILink createLink(ITeamRepository teamRepository, IWorkItemHandle workItemHandle, IWorkItem workItem, IBuildResult result)
throws TeamRepositoryException {
IBuildDefinition definition = (IBuildDefinition) teamRepository.itemManager().fetchCompleteItem(
result.getBuildDefinition(), IItemManager.DEFAULT, null);
IHelperType helperType = IHelperType.IRegistry.INSTANCE.getHelperType(
LinksPackage.eINSTANCE.getReference().getName(), LinksPackage.eNS_URI);
String sourceComment = ItemHelper.validateStringAttributeLength(definition.getId() + " " + result.getLabel(), //$NON-NLS-1$
helperType, LinksPackage.eINSTANCE.getReference_Comment().getName());
IReference source = IReferenceFactory.INSTANCE.createReferenceToItem(result, sourceComment);
IReference target;
if (workItem == null) {
// work item is missing or invisible, so create a link but provide no comment
target = IReferenceFactory.INSTANCE.createReferenceToItem(workItemHandle);
} else {
String targetComment = ItemHelper.validateStringAttributeLength(
WorkItemTextUtilities.getWorkItemText(workItem), helperType,
LinksPackage.eINSTANCE.getReference_Comment().getName());
target = IReferenceFactory.INSTANCE.createReferenceToItem(workItemHandle, targetComment);
}
return ILinkFactory.INSTANCE.createLink(BuildLinkTypes.INCLUDED_WORK_ITEMS, source, target);
}
Comments
when I use the eclipse gui, it reports the build result has no start request. Can this be the problem?
Is their any way of debuging this problem?
If I add a IBuildRequest buildRequest, I can now see most of the the build results
All except workitems associated with the results.
I add the work items to the result using
contribution = BuildItemFactory.createBuildResultContribution();
contribution.setExtendedContributionTypeId(WorkItemConstants.EXTENDED_DATA_TYPE_ID);
contribution.setImpactsPrimaryResult(false);
if ((handleIds != null) && (handleIds.length != 0)) {
contribution.setExtendedContributionData(ContentUtil.stringArrayToContent(repo, handleIds,'\n'));
}
result = buildClient.addBuildResultContribution(result, contribution,IBuildResult.PROPERTIES_COMPLETE, null);
I do not link the work item to the build result